from termcolor import colored
class QueryTaskPrinter:
    def __init__(self, logger):
        self.logger = logger

    def print_valid_tasks(self, valid_tasks):
        """打印有效任务数据"""
        self.logger.info(colored(f"{'有效数据:':<20}", "green"))
        self.logger.info("-" * 50)  # 分隔线

        for task in valid_tasks:
            task_id = task.get('task_id', '')
            task_status = task.get('task_status', '')
            speech_url = task.get('task_result', {}).get('speech_url', '')
            
            self.logger.info(f"  Task ID: {task_id}")
            self.logger.info(f"  Task Status: {task_status}")
            self.logger.info(f"  Speech URL: {speech_url}")
            self.logger.info("-" * 50)
    

    def print_invalid_tasks(self, invalid_tasks):
        """打印无效任务数据"""
        self.logger.info(colored(f"{'无效数据:':<20}", "red"))
        self.logger.info("-" * 50)
        self.logger.info(f"  {invalid_tasks}")
        self.logger.info("=" * 50)

    def print_task_results(self, valid_tasks, invalid_tasks):
        """打印任务查询结果（有效与无效数据）"""
        self.logger.info("=" * 50)
        self.logger.info(colored(f"{'任务查询结果:':^50}", "yellow"))
        self.logger.info("=" * 50)

        # 打印有效数据
        if valid_tasks:
            self.print_valid_tasks(valid_tasks)

        # 打印无效数据
        if invalid_tasks:
            self.print_invalid_tasks(invalid_tasks)

